package com.wilmer.aiUserChat.service.impl;

import java.util.List;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import com.wilmer.common.utils.DateUtils;
import com.wilmer.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wilmer.aiUserChat.mapper.YwUserChatMapper;
import com.wilmer.aiUserChat.domain.YwUserChat;
import com.wilmer.aiUserChat.service.IYwUserChatService;

/**
 * 聊天列表Service业务层处理
 *
 * @author hans
 * @date 2024-05-15
 */
@Service
public class YwUserChatServiceImpl implements IYwUserChatService
{
    @Autowired
    private YwUserChatMapper ywUserChatMapper;

    /**
     * 查询聊天列表
     *
     * @param chatId 聊天列表主键
     * @return 聊天列表
     */
    @Override
    public YwUserChat selectYwUserChatByChatId(String chatId)
    {
        return ywUserChatMapper.selectYwUserChatByChatId(chatId);
    }

    /**
     * 查询聊天列表列表
     *
     * @param ywUserChat 聊天列表
     * @return 聊天列表
     */
    @Override
    public List<YwUserChat> selectYwUserChatList(YwUserChat ywUserChat)
    {
        ywUserChat.setUserId(SecurityUtils.getUserId());
        return ywUserChatMapper.selectYwUserChatList(ywUserChat);
    }

    /**
     * 新增聊天列表
     *
     * @param ywUserChat 聊天列表
     * @return 结果
     */
    @Override
    public int insertYwUserChat(YwUserChat ywUserChat)
    {

        ywUserChat.setChatId(IdUtil.objectId());
        ywUserChat.setCreateTime(DateUtils.getNowDate());
        ywUserChat.setDeptId(SecurityUtils.getDeptId());
        ywUserChat.setUserId(SecurityUtils.getUserId());
        ywUserChat.setChatName("新对话");
        //创建对话，这个聊天就是在最顶部的
        ywUserChat.setChatTop("1");
        return ywUserChatMapper.insertYwUserChat(ywUserChat);
    }

    /**
     * 修改聊天列表
     *
     * @param ywUserChat 聊天列表
     * @return 结果
     */
    @Override
    public int updateYwUserChat(YwUserChat ywUserChat)
    {
        ywUserChat.setUpdateTime(DateUtils.getNowDate());
        return ywUserChatMapper.updateYwUserChat(ywUserChat);
    }

    /**
     * 批量删除聊天列表
     *
     * @param chatIds 需要删除的聊天列表主键
     * @return 结果
     */
    @Override
    public int deleteYwUserChatByChatIds(String[] chatIds)
    {
        return ywUserChatMapper.deleteYwUserChatByChatIds(chatIds);
    }

    /**
     * 删除聊天列表信息
     *
     * @param chatId 聊天列表主键
     * @return 结果
     */
    @Override
    public int deleteYwUserChatByChatId(Long chatId)
    {
        return ywUserChatMapper.deleteYwUserChatByChatId(chatId);
    }
}
